home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / overview / dtscpluslibrary / sources / graphicsenvtest.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  3.9 KB  |  160 lines

  1. /*
  2.     File:        GraphicsEnvTest.cp
  3.  
  4.     Contains:    GraphicsEnvTest.cp contains the needed test functions for testing out graphics
  5.                 environment utility classes.
  6.  
  7.     Written by:     
  8.  
  9.     Copyright:    Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. */
  24. // HEADER FILES
  25. // Main interface for the application framework
  26. #ifndef _APPLICATION_
  27. #include "Application.h"
  28. #endif
  29.  
  30. // For graphics environment testing
  31. #ifndef _GRAPHICSENV_
  32. #include "GraphicsEnv.h"
  33. #endif
  34.  
  35. // CONSTANTS
  36. const short H = 10;                                // horizontal offset of graphics drawing in window
  37. const short V = 20;                                // initial vertical offset of graphics in window
  38. const short DELTA = 15;                            // delta value of vertical offsets 
  39.  
  40.  
  41. // CLASSES
  42. class TMyApplication : public TGUIApplication
  43. // Our sub-TApplication class, override DoCreateDocument for creation of a special window.
  44. {
  45. public:
  46.     TMyApplication();
  47.     virtual void DoCreateDocument();
  48. };
  49.  
  50.  
  51. class TMyWindow : public TWindow
  52. // Override Draw to specify what is drawn in the window.
  53. {
  54. public:
  55.     virtual void Draw();
  56. };
  57.  
  58.  
  59. TMyApplication::TMyApplication()
  60. {
  61. }
  62.  
  63.  
  64. // MEMBER FUNCTIONS
  65. #pragma segment Application
  66. void TMyApplication::DoCreateDocument()
  67. {
  68.     Str255 myTitle;
  69.     Pstrcpy(myTitle, "\pGraphics Env. Tests");
  70.  
  71.     // Create this time my TMyWindow document, and add it to the TApplication list.
  72.     TMyWindow * aWindow = new TMyWindow;
  73.     aWindow->SetTitle(&myTitle);
  74.     this->AddDocument(aWindow);
  75.  
  76.     // Quick test, show and hide the window.
  77.     aWindow->Hide();
  78.     Delay(60 * 1, NULL);
  79.     aWindow->Show();
  80. }
  81.  
  82.  
  83. // Global styles
  84. TFontEnvironment myGenevaBold(srcOr,
  85.                               kFontIDGeneva,
  86.                               9,
  87.                               bold);
  88. TFontEnvironment myGenevaInvBold(notSrcCopy,
  89.                                  kFontIDGeneva,
  90.                                  10,
  91.                                  bold);
  92.  
  93. TPenEnvironment myThickLine(srcOr,
  94.                             qd. dkGray,
  95.                             5,
  96.                             5);
  97.  
  98. TColorEnvironment myMetalGray(36000,
  99.                               40500,
  100.                               37500);
  101. TColorEnvironment myMetalBlue(26312,
  102.                               14340,
  103.                               47359);
  104.  
  105.  
  106. #pragma segment Window
  107. void TMyWindow::Draw()
  108. {
  109.     // Paint background in metal color
  110.     myMetalGray.SetForeground();                // set gray foreground
  111.     Rect windowRect = this->GetExtent();        // get window extent
  112.     ::PaintRect(&windowRect);                    // paint background with gray
  113.  
  114.     // Set real background & foreground colors
  115.     myMetalBlue.SetForeground();                // set blue paint foreground
  116.     myMetalGray.SetBackground();                // set gray background
  117.  
  118.     // Draw something into my special window.
  119.     ::MoveTo(H, V);
  120.     myGenevaBold.Set();
  121.     ::DrawString("\pThis is a color and Quickdraw test.");
  122.  
  123.     ::MoveTo(H, V + DELTA);
  124.     myGenevaInvBold.Set();
  125.     ::DrawString("\pI will use various classes, do");
  126.  
  127.     ::MoveTo(H, V + 2 * DELTA);
  128.     myGenevaBold.Reset();                        // reset font values to default state
  129.     ::DrawString("\pthey they work or not?");
  130.  
  131.     ::MoveTo(H, V + 3 * DELTA);
  132.     myThickLine.Set();                            // draw thick line
  133.     ::Line(200, 0);
  134.     myThickLine.Reset();                        // back to thin lines
  135.     ::MoveTo(H, V + 4 * DELTA);
  136.     ::Line(200, 0);
  137.     ::MoveTo(H, V + 5 * DELTA);
  138.     ::Line(200, 0);
  139.  
  140.     ::PenNormal();                                // restore pen
  141. }
  142.  
  143.  
  144. // M A I N   F U N C T I O N
  145. void main(void)
  146. {
  147.     TMyApplication * myApp = new TMyApplication;
  148.     myApp->Start();
  149. }
  150.  
  151.  
  152. // _________________________________________________________________________________________________________ //
  153.  
  154. /*    Change History (most recent last):
  155.   No        Init.    Date        Comment
  156.   1            khs        1/2/93        New file
  157.   2            khs        1/7/93        Cleanup
  158. */
  159.  
  160.